<?php include '../../authorization_check.php' ?>
<?php include '../../checkSecretaryOnly.php' ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>Edit Section</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>
</head>
<style type="text/css">
  th {text-align: right}  
</style>
<body>

<?php include 'top.html' ?>

<?php include 'notifier.php' ?>
  
<FORM NAME ="form1" METHOD ="POST" ACTION = "EditSection.php">

<?php
  require_once '../../commonutils/db/DBConnectionManager.php';
  if (isset($_POST['btnSubmit']))
  {
  	//echo "1111 <br>";
  	$sectionID = $_POST['txtSection'];
	//$sectionID = $_POST['sectionID'];
	$instructorID = $_POST['instructorGroup'];
	$beginTime = $_POST['sho'].":40";
	$room = $_POST['room'];	
	$hours = $_POST['hours'];
	$lectureDay = $_POST['group2'];
	
	
	$sqlquery = " update section set instructorID = ". $instructorID
				." , roomCode = '". $room . "'"
				." , beginTime = '". $beginTime . "'"
				." , hours = ". $hours
				." , lectureDay = ". $lectureDay
				." where sectionID = ". $sectionID ;
				
	// echo $sqlquery;
	DBConnectionManager::query($sqlquery);
	
	echo "<p><font color=blue><b>You have successfully edited the section details.</b></font></p>";
	echo "<p><a href=ViewSections.php> View sections. </a></p>";
  }
  else
  {
  	//echo "2222 <br>";
  	$sectionID = $_POST['group1'];
  }
  
  $sqlquery = " select s.sectionID, c.courseCode, c.courseName, s.sectionNumber, s.instructorID, ".
  				" s.roomCode, s.beginTime, s.hours, s.lectureDay ".
				" from course c, section s ".
				" where s.courseCode = c.courseCode  ".
  				" and s.semesterID = ".$semesterID." and c.programCode = ".$programCode.
				" and s.sectionID = ".$sectionID;
 //// echo $sqlquery;
 $result = DBConnectionManager::query($sqlquery);
 $row = mysql_fetch_assoc($result);
 $courseCode = $row['courseCode'];
 $courseName = $row['courseName'];
 $sectionNumber = $row['sectionNumber'];
 $instructorID = $row['instructorID'];
 $room = $row['roomCode'];
 $beginTime = $row['beginTime'];
 $bhh = substr($beginTime, 0, 2);
 $bmm = substr($beginTime, 3, 2);
 $hours = $row['hours'];
 $lectureDay = $row['lectureDay'];
 
?>

<table>
<tr>
<th>Course Code: </th>
<td><?php echo $courseCode ?></td>
</tr>
<tr>
<th>Course Name: </th>
<td><?php echo $courseName ?></td>
</tr>
<tr>
<th>Section number: </th>
<td><?php echo $sectionNumber ?></td>
</tr>
</table>

<table border=1 cellpadding="3">
<tr>
<td >
<table border=1 cellpadding="3">
<tr>
<th style="text-align:center">INSTRUCTOR </th>
</tr>
<?php
	$sqlquery = " select instructorID, concat(firstName, ' ', lastName) as iname from instructor ";
	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		if($row['instructorID'] == $instructorID)
		  $chk = "checked";
		else 
		  $chk = "";
		echo "<tr>";
		echo "<td><input type=radio name=instructorGroup value= ".$row['instructorID']." ".$chk." \"> ";
		echo " ".$row['iname']."</td>";

		echo "</tr>";		
	}	
?>
</table>
</td>

<td>
<table cellpadding=3>

<tr>
<td >Day Of Week: </br> <hr>

<input type="radio" name="group2" value="1" <?php if($lectureDay == 1) {echo "checked"; }?>/>Monday</br>
<input type="radio" name="group2" value="2" <?php if($lectureDay == 2) {echo "checked"; }?>/>Tuesday</br>
<input type="radio" name="group2" value="3" <?php if($lectureDay == 3) {echo "checked"; }?>/>Wednesday</br>
<input type="radio" name="group2" value="4" <?php if($lectureDay == 4) {echo "checked"; }?>/>Thursday</br>
<input type="radio" name="group2" value="5" <?php if($lectureDay == 5) {echo "checked"; }?>/>Friday</br>
<input type="radio" name="group2" value="6" <?php if($lectureDay == 6) {echo "checked"; }?>/>Saturday</br>
<input type="radio" name="group2" value="7" <?php if($lectureDay == 7) {echo "checked"; }?>/>Sunday</br>
</td>
</tr>

<tr>
<td>
<b> Start Time(HH:MM): </b> 
<select name="sho" > 
	<option value="08" <?php if($bhh == "08") echo "selected"; ?> >08</option>
	<option value="09" <?php if($bhh == "09") echo "selected"; ?> >09</option>
	<option value="10" <?php if($bhh == "10") echo "selected"; ?> >10</option>
	<option value="11" <?php if($bhh == "11") echo "selected"; ?> >11</option>
	<option value="12" <?php if($bhh == "12") echo "selected"; ?> >12</option>
	<option value="13" <?php if($bhh == "13") echo "selected"; ?> >13</option>
	<option value="14" <?php if($bhh == "14") echo "selected"; ?> >14</option>
	<option value="15" <?php if($bhh == "15") echo "selected"; ?> >15</option>
	<option value="16" <?php if($bhh == "16") echo "selected"; ?> >16</option>
	<option value="17" <?php if($bhh == "17") echo "selected"; ?> >17</option>
	<option value="18" <?php if($bhh == "18") echo "selected"; ?> >18</option>
	<option value="19" <?php if($bhh == "19") echo "selected"; ?> >19</option>
</select>
 : 40 
</td>
</tr>

<tr>
<td>
<b> Hours: </b> 
<select name="hours" >  
    <option value="1" <?php if($hours == 1) echo "selected"; ?>>1</option>
    <option value="2" <?php if($hours == 2) echo "selected"; ?>>2</option>
    <option value="3" <?php if($hours == 3) echo "selected"; ?>>3</option>
    <option value="4" <?php if($hours == 4) echo "selected"; ?>>4</option>
    <option value="5" <?php if($hours == 5) echo "selected"; ?>>5</option>
    <option value="6" <?php if($hours == 6) echo "selected"; ?>>6</option>
</select>
</td>
</tr>

<tr>
<td><b>Room:</b> <input type="text" name="room" size="10" value="<?php echo $room ?>"/></td>
</tr>
<tr>
</table>

</table>

</p>

<input type="submit" value="Submit" name="btnSubmit">

<input type="reset" value="Reset" name="btnReset"></p>  
</p>  

<input value="<?php echo $sectionID ?>" type="text" name="txtSection" 
style="position:absolute;left:0px;top:-500px;width:1px;height:1px;overflow:hidden;" />

</FORM>

<?php include 'bottom.php' ?>

</body>


</html>